<?php

class KayitController extends AppController {

	var $helpers = array('Html', 'Form', 'Captcha');
	
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->allow('login', 'logout', 'index', 'captcha');
	}
	
	/**
	 * kayit view'ini gösterir
	 */
	public function index () {
		$this->autoRender = true;
		$this->layout=null;
		/*
		 $this->Kullanici->recursive = 0;
		$this->set('kullanicis', $this->paginate());
		*/
		
		//eğer captha doğruysa
		
		$proje = ClassRegistry::init('Proje');
		$projeId = $this->request->query('_pid');
		$proje->id = $projeId;
		$data = $proje->find('first', array(
			'fields' => array('baslik', 'kod'),
			'conditions' => array('id =' => $projeId)
		));
		
// 		debug($data, true);
		$this->set('projeId', $projeId);
		$this->set('proje', count($data) == 0 ? null : $data);
	}
	
	public function captcha()        {
		$this->autoRender = false;
		$this->layout='ajax';
		if(!isset($this->Captcha))        { //if Component was not loaded throug $components array()
			$this->Captcha = $this->Components->load('Captcha', array(
					'width' => 150,
					'height' => 50,
					'theme' => 'random', //possible values : default, random ; No value means 'default'
			)); //load it
		}
		$this->Captcha->create();
	}
	
	function add()        {
		$this->Captcha = $this->Components->load('Captcha', array('captchaType'=>'math', 'jquerylib'=>true, 'modelName'=>'Signup', 'fieldName'=>'captcha')); //load it
	
		if(!empty($this->request->data))        {
			/*if(!isset($this->Captcha))        { //if Component was not loaded throug $components array()
			 $this->Captcha = $this->Components->load('Captcha'); //load it
			}*/
			$this->Signup->setCaptcha($this->Captcha->getVerCode()); //getting from component and passing to model to make proper validation check
			$this->Signup->set($this->request->data);
			if($this->Signup->validates())        { //as usual data save call
				//$this->Signup->save($this->request->data);//save or something
				// validation passed, do something
				$this->Session->setFlash('Data Validation Success', 'default', array('class' => 'notice success'));
			}        else        { //or
				$this->Session->setFlash('Data Validation Failure', 'default', array('class' => 'cake-error'));
				//pr($this->Signup->validationErrors);
				//something do something else
			}
		}
	}

}